package com.rjxy.plansystemmanagement.mapper;

import com.rjxy.plansystemmanagement.entity.yh.YhCode;
import com.rjxy.plansystemmanagement.entity.yh.YhCoupon;
import com.rjxy.plansystemmanagement.entity.yh.YhUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface YhMapper {
    @Select("select * from yh_coupon where status=2")
    List<YhCoupon> getIssuedCoupon();

    @Insert("insert into yh_user(user_id,coupon_id,status) values (#{user_id},#{coupon_id},#{status})")
    void addYhUser(YhUser yhUser);

    List<YhCoupon> getCouponByUid(Integer id);

    @Select("select * from yh_code where code = #{code}")
    YhCode selectCode(String code);

    @Update("update yh_code set user_id = #{user_id} where id = #{id}")
    void updateYhCode(YhCode yhCode);

    @Select("select * from yh_user where status = #{status}")
    List<YhUser> getYhUserByStatus(Integer status);

    @Select("select * from yh_coupon where id = #{id}")
    List<YhCoupon> getCouponsByCouponId(Integer id);

    void updateYhUser(YhUser yhUser);
    @Select("SELECT * from yh_coupon")
    List<YhCoupon> yhCouponList();

    void updateYhCoupon(YhCoupon yhCoupon);
    @Select("SELECT * from yh_code where coupon_id = #{couponID}")
    YhCode selectCodeByCouponId(Integer couponId);

    @Insert("insert into yh_code(code,status,coupon_id) values (#{code},#{status},#{coupon_id})")
    void addYhCode(YhCode yhCode);

    @Insert("INSERT INTO yh_coupon (name, discount_type, discount_value, threshold_amount, obtain_way, " +
            "status, total_num, user_limit, used_num, term_begin_time, term_end_time, point) " +
            "VALUES (#{name}, #{discount_type}, #{discount_value}, #{threshold_amount}, #{obtain_way}, " +
            "#{status}, #{total_num}, #{user_limit}, #{used_num}, #{term_begin_time}, #{term_end_time}, #{point})")
    void addYhCoupon(YhCoupon yhCoupon);

    @Delete("DELETE FROM yh_coupon WHERE id = #{id}")
    void deleteYhCoupon(Integer id);

    @Delete("DELETE FROM yh_code WHERE coupon_id = #{couponId}")
    void deleteYhCode(Integer couponId);
}
